<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Gps_log_source extends CI_Model
{

	var $table_name = "gps_log_source";

	function __construct()
	{
		parent::__construct();
	}

	function insert_log($uid, $filename, $upload_time, $gen_time, $description)
	{
	
		$data = array();
		//通用信息
		$data['uid'] 		= $uid;
		$data['filename'] 	= $filename; 
		$data['upload_time']	= $upload_time;
		$data['gen_time']	= $gen_time;
		$data['description']	= $description;
						
		$this->db->insert($this->table_name, $data);
		return $this->db->insert_id();
	}
	
	function get_source_file($uid, $sid)
	{
		//$this->db->select("pid");
		$this->db->where("uid", $uid);
		$this->db->where("sid", $sid);
		$query = $this->db->get($this->table_name);
		if ($query->num_rows() > 0)
			return $query->row();
		else
		  	return false;
	}
	
	function get_unparsed_list($uid)
	{
		$this->db->where("uid", $uid);
		$this->db->where("track_num", 0);
		$query = $this->db->get($this->table_name);
		if ($query->num_rows() > 0)
			return $query->result_array();
		else
		  	return false;
	}
	
	function add_remove_tracks($uid, $sid, $add = true)
	{
		if ($add) $op = "+1";
		else $op = "-1";

		$this->db->where("uid", $uid);
		$this->db->where("sid", $sid);
		$this->db->set("track_num", "track_num".$op, FALSE);
		$this->db->update($this->table_name);
	}

}

?>